/**
 * @author LYJ
 * Created by Administrator on 2018/1/17 0017.
 */
;(function($, window, document,undefined) {
    var defaultParams = {
        backdrop:false,
        show:false
    };

    var HintModal = function ($element,options) {
        this.$element = $element;
        this.defaults = defaultParams;
        this.options = this.$element.extend({}, this.defaults, options);
        this.init();
    };

    HintModal.prototype = {
        init:function () {
            this.$element.modal(this.options);
            this.$element.modal('hide');
        },
        showError:function (content ,time) {
            var $element = this.$element;
            var html = '' +
                '<div class="modal-dialog">' +
                '<div class="modal-content">' +
                '<div class="modal-body">' +
                content +
                '</div>' +
                '</div>' +
                '</div>';
            $element.html(html);
            $element.addClass("modal fade");
            $element.modal('show');
            setTimeout(function () {
                $element.modal('hide');
            }, time == null ? 1200 : time);
        },
        showHint: function(content,qd_event,qx_event) {
            var $element = this.$element;
            var html = '' +
                '<div class="modal-dialog">' +
                    '<div class="modal-content">' +
                        '<div class="modal-body">' +
                            content +
                        '</div>' +
                        '<div class="modal-footer">' +
                            '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
                            '<button type="button" class="btn btn-primary">确定</button>' +
                        '</div>' +
                    '</div>' +
                '</div>';
            $element.html(html);
            $element.addClass("modal fade");
            if(qd_event != null){
                $element.find(".btn-primary").on("click",function () {
                    qd_event($element.find(".btn-primary"));
                });
            }
            if(qx_event != null){
                $element.find(".btn-default").on("click",function () {
                    qx_event();
                });
            }
            $element.modal('show');
        },
        showDiv: function (params) {
            if(params != null){
                this.$element.modal(params);
            }
            this.$element.modal({backdrop:true});
            this.$element.modal('show');
        },
        showTheCustom: function (html) {
            var $element = this.$element;
            $element.html(html);
            $element.addClass("modal fade");
            $element.modal('show');
        },
        hide: function () {
            this.$element.modal('hide');
        }
        // on: function (event,method) {
        //     this.$element.on(event,method);
        // }
    };



    //在插件中使用Beautifier对象
    $.fn.hintModal = function(options) {
        var $this = $(this);
        var data = $this.data('bs.hintModal');
        if(!data){
            data = new HintModal($this,options);
            $this.data('bs.hintModal',data);
        }
        return data;
    };

})(jQuery, window, document);